package com.spkj.srb.easyexcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.spkj.srb.easyexcel.pojo.dto.ExcelStudentDTO;

import java.io.File;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author spkj
 * @create 2022-06-15 20:09
 */
public class Test {
    public static void main(String[] args) {
//        write();
        EasyExcel.read(new File("e:/student.xlsx"), ExcelStudentDTO.class,
                new ExcelStudentListener()).sheet("sheet1").doRead();
    }

    private static void write() {
        List<ExcelStudentDTO> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            ExcelStudentDTO excelStudentDTO = new ExcelStudentDTO();
            excelStudentDTO.setName("小 " + i);
            excelStudentDTO.setSalary(100D + i);
            excelStudentDTO.setBirthday(new Date());
            list.add(excelStudentDTO);
        }
//        EasyExcel.write(new File("e:/student.xlsx"), ExcelStudentDTO.class)
//                .sheet("sheet1").doWrite(list);
        ExcelWriter excelWrite = EasyExcel.write(new File("e:/student.xlsx"), ExcelStudentDTO.class)
                .build();
        WriteSheet sheet1 = EasyExcel.writerSheet("sheet1").build();
        WriteSheet sheet2 = EasyExcel.writerSheet("sheet2").build();
        excelWrite.write(list, sheet1);
        excelWrite.write(new ArrayList(), sheet2);
        excelWrite.finish();
    }
}
